<template>
  <div class="page-container">
    <!-- 导航栏 -->
    <div class="header">
      <div class="header-content">
        <div class="header-left">
          <button @click="$router.back()" class="back-btn">
            <i class="fas fa-arrow-left"></i>
          </button>
          <h1 class="header-title">我的点赞</h1>
        </div>
        <!-- <button class="clear-btn">清空</button> -->
      </div>
    </div>

    <!-- 内容区域 -->
    <div class="content-area">
      <!-- 加载状态 -->
      <div v-if="loading" class="loading-container">
        <div class="loading-spinner"></div>
        <p class="loading-text">正在加载数据...</p>
      </div>

      <!-- 收藏列表 -->
      <div v-else-if="ratings.length > 0" class="ratings-list">
        <div class="rating-item" v-for="item in ratings" :key="item.id" @click="toPlayer(item.id)">
          <div class="item-content">
            <div class="cover-container">
              <img :src="item.cover" class="cover-image" :alt="item.title" />
              <div class="heart-icon">
                <i class="fas fa-heart"></i>
              </div>
            </div>
            <div class="item-info">
              <h4 class="item-title">{{ item.title }}</h4>
              <p class="item-meta">
                <span class="tag" v-for="(value, index) in item.tags" :key="index">{{ value }}</span>
                · 全{{ item.totalEpisodes }}集
              </p>
              <div class="item-footer">
                <span class="favorite-time">收藏于 {{ item.favoriteTime }}</span>
                <div class="action-buttons">
                  <button class="watch-btn">观看</button>
                  <!-- <button class="unfavorite-btn">取消收藏</button> -->
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

      <!-- 空状态 -->
      <div v-else class="empty-state">
        <i class="fas fa-heart empty-icon"></i>
        <h3 class="empty-title">暂无点赞内容</h3>
        <p class="empty-desc">发现喜欢的内容，点击收藏吧</p>
      </div>
    </div>

    <!-- Toast提示 -->
    <div v-if="showToast" class="toast-message">
      {{ toastMessage }}
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { reqLikedDramas } from '@/apis/video'

const router = useRouter()

// 点赞列表
const ratings = ref([])
// 加载状态
const loading = ref(true)
// 提示消息
const toastMessage = ref('')
const showToast = ref(false)

// 显示提示消息
const showToastMessage = (message) => {
  toastMessage.value = message
  showToast.value = true
  setTimeout(() => {
    showToast.value = false
  }, 2000)
}

const toPlayer = (id) => {
  router.push({ name: 'Player', params: { dramaId: id } })
}

// 获取点赞列表
const fetchRatings = async () => {
  try {
    loading.value = true
    const response = await reqLikedDramas()
    console.log('点赞列表:', response.data.list)
    ratings.value = response.data.list || []

    if (!response.data.list || response.data.list.length === 0) {
      showToastMessage('暂无点赞内容')
    }
  } catch (error) {
    console.error('获取点赞列表失败:', error)
    showToastMessage('获取数据失败，请稍后重试')
  } finally {
    loading.value = false
  }
}

onMounted(() => {
  fetchRatings()
})
</script>

<style scoped>
.page-container {
  width: 100%;
  min-height: 100vh;
  background-color: #f9fafb;
  position: relative;
}

.header {
  background-color: white;
  border-bottom: 1px solid #f3f4f6;
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
}

.header-left {
  display: flex;
  align-items: center;
}

.back-btn {
  margin-right: 16px;
  color: #6b7280;
  background: none;
  border: none;
  cursor: pointer;
}

.header-title {
  font-size: 18px;
  font-weight: 600;
  color: #1f2937;
  margin: 0;
}

.clear-btn {
  color: #2563eb;
  font-size: 14px;
  font-weight: 500;
  background: none;
  border: none;
  cursor: pointer;
}

.content-area {
  padding: 24px 16px 80px;
}

.loading-container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 3rem 0;
  height: 30vh;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(0, 0, 0, 0.1);
  border-top-color: #f97316;
  border-radius: 50%;
  animation: spin 1s ease-in-out infinite;
  margin-bottom: 1rem;
}

.loading-text {
  color: #666;
  font-size: 1rem;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.ratings-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.rating-item {
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
  overflow: hidden;
  cursor: pointer;
}

.item-content {
  display: flex;
  padding: 16px;
}

.cover-container {
  width: 80px;
  height: 96px;
  background: linear-gradient(to bottom right, #10b981, #0d9488);
  border-radius: 8px;
  margin-right: 12px;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

.cover-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.heart-icon {
  position: absolute;
  top: 4px;
  right: 4px;
  background-color: #f87171;
  color: white;
  font-size: 12px;
  padding: 4px 4px 0;
  border-radius: 4px;
}

.item-info {
  flex: 1;
  min-width: 0;
}

.item-title {
  font-weight: 500;
  color: #1f2937;
  margin: 0 0 4px 0;
}

.item-meta {
  font-size: 14px;
  color: #6b7280;
  margin: 0 0 8px 0;
}

.tag {
  margin-right: 4px;
}

.item-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.favorite-time {
  font-size: 14px;
  color: #9ca3af;
}

.action-buttons {
  display: flex;
  gap: 8px;
}

.watch-btn {
  color: #2563eb;
  font-size: 14px;
  background: none;
  border: none;
  cursor: pointer;
}

.watch-btn:hover {
  color: #1d4ed8;
}

.unfavorite-btn {
  color: #dc2626;
  font-size: 14px;
  background: none;
  border: none;
  cursor: pointer;
}

.unfavorite-btn:hover {
  color: #b91c1c;
}

.empty-state {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 3rem 0;
  height: 30vh;
  text-align: center;
}

.empty-icon {
  color: #d1d5db;
  font-size: 3rem;
  margin-bottom: 1rem;
}

.empty-title {
  color: #6b7280;
  font-weight: 500;
  margin: 0 0 8px 0;
}

.empty-desc {
  color: #9ca3af;
  font-size: 14px;
  margin: 0;
}

.toast-message {
  position: fixed;
  bottom: 5rem;
  left: 50%;
  transform: translateX(-50%);
  background-color: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  z-index: 50;
}
</style>
